<template>
    <view>
		<dataTable :thList="thList" :isflag="isflag" :colWidthList="colWidthList" :thBgColor="fontcolor.color" thColor="#fff" thSize="30"
		    thHeight="70" :borderColor="fontcolor.color" :tbList="tbList">
		</dataTable>
		 <mx-date-picker  style="" :show="showPicker" :type="type" :value="value" :show-tips="true"  :show-seconds="true" @confirm="ed" @cancel="ed" />
    </view>
</template>

<script>
	import dataTable from '../../components/lun-dataTable/lun-dataTable.vue'
	import MxDatePicker from "@/components/mx-datepicker/mx-datepicker.vue";
	export default {
		components: {
			dataTable,
			MxDatePicker
		},
		data() {
			return {
				fontcolor:{
				color:this.$kdup.color,
				borderBottom:'2px solid '+this.$kdup.color
				},
				bj:{
				backgroundColor:this.$kdup.color,
				},
				color:this.$kdup.color,
				date: this.addDate(new Date(),90),
				type: 'date',
				showPicker: false,
				value: '',
				isflag:"1",
				flag:"1",
				thList: ['订单号','订单行号', '单据日期', '产品编码', '产品名称', '产品型号', '订单状态','计划开工时间','计划完工时间', '计划数量',
				  '入库数量','未入库数量'],
				colWidthList: ['250', '150', '200' , '300', '800', '800', '200' , '200'
				, '200', '250', '200', '200'],
				tbList: [
				 //    ['MO20211111001', '1', '2.1.05.01.01.05',
					// '胶件8S317三芯盖','胶件8S317三芯盖', '2021-12-11','2021-12-11','100.00',
					//  '100.00', '100.00', '100.00'],
				],
				curWord:""
			}
		},
		onLoad() {  
			uni.setNavigationBarColor({
				frontColor: "#ffffff",	//文字颜色
				backgroundColor: this.$kdup.color	//底部背景色
			})
			this.InitData("",this.date);
		},
		methods: {
	      InitData(currentValue,datetime){//MO20210312042-1
		  uni.showLoading({title: '数据加载中',mask:true});
		      if(currentValue.indexOf("seq") != -1 && currentValue.indexOf("src") != -1){
				currentValue=this.OJSCRKgetbarvalue(currentValue).src+"-"+ this.OJSCRKgetbarvalue(currentValue).seq;
			  }
			  var data={currentValue:currentValue,datetime:datetime};
			  this.$myRequest.postRequest("GetInstockList", data).then(res => {
				 this.tbList=[];
				if (!this.$kdup.isEmpty(res.data.error)) {
								 uni.showToast({
								 	title:"找不到生产订单！",
								 	duration: 2000,
									icon: "none"
								 });
								return;
				}
				for(var i=0;i<res.data.Table.length;i++){
				 this.tbList.push(Object.values(res.data.Table[i]));	
				}
					setTimeout(function () {uni.hideLoading();}, 100);
			   })
		  },
		  DatePicker(type){//显示
		      this.type = type;
		      this.showPicker = true;
		      this.value = this[type];
		  },
		  ed(e) {//选择
		      this.showPicker = false;
		      if(e) {
		          this[this.type] = e.value; 
		          this.date=e.value;
				 this.InitData(this.curWord,this.date);
		      }
		  },
		  onNavigationBarSearchInputConfirmed(e) {
			this.curWord = e.text 
			this.InitData(this.curWord,this.date);
		  },
		  onNavigationBarSearchInputChanged(e) {
		 	this.curWord = e.text 
			this.InitData(this.curWord,this.date);
		  },
		  onNavigationBarButtonTap(e) {
		  this.DatePicker('date');
		  },
		  OJSCRKgetbarvalue: function(val) {
		  	var srcIndex = val.indexOf("src:");
		  	var seqIndex = val.indexOf("seq:");
		  	return {
		  		src: val.substring(srcIndex + 4, seqIndex),
		  		seq: val.substring(seqIndex + 4,val.length)
		  	}
		  },
		  //获取今天日期，格式YYYY-MM-DD
		  addDate(date, days) {
			   if(days == undefined || days == '') {
				   days = 1;
			   }
			   var date = new Date(date);
			   date.setDate(date.getDate() - days);
			  var month = date.getMonth() + 1;
			  var day = date.getDate();
			  var mm = "'" + month + "'";
			  var dd = "'" + day + "'";
			  
			  //单位数前面加0
			  if(mm.length == 3) {
				  month = "0" + month;
			  }
			  if(dd.length == 3) {
				  day = "0" + day;
			  }
			  var time = date.getFullYear() + "-" + month + "-" + day
			  return time;
		   }
		}
	}
</script>

<style>

</style>
